package com.zhb.cloud.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zhb.cloud.exception.ServiceException;
import com.zhb.cloud.mapper.UserInfoMapper;
import com.zhb.cloud.model.UserInfo;
import com.zhb.cloud.model.UserInfoExample;
import com.zhb.cloud.model.UserInfoExample.Criteria;
import com.zhb.cloud.service.UserInfoService;

/**
 * @ClassName: UserInfoServiceImpl
 * @Description: 实现
 * @author: zhb1316783262@163.com
 * @date: 2019年4月17日下午4:54:53
 */
@Service
public class UserInfoServiceImpl extends GeneralServiceImpl<UserInfo> implements UserInfoService {

	@Autowired
	private UserInfoMapper userInfoMapper;

	@Override
	public UserInfo findByUserName(String userName) {
		return this.userInfoMapper.findByUserName(userName).orElseThrow(() -> new ServiceException("用户不存在"));
	}

	@Override
	public List<UserInfo> findByUserNameAndPhone(String userName, String phone) {
		UserInfoExample userInfoExample = new UserInfoExample();
		Criteria criteria = userInfoExample.createCriteria();
		criteria.andUserNameLike(userName);
		criteria.andPhoneLike(phone);
		return userInfoMapper.selectByExample(userInfoExample);
	}

	@Override
	public UserInfo findByPhone(String phone) {
		return userInfoMapper.findByPhone(phone).orElseThrow(() -> new ServiceException("手机号不存在"));
	}
}
